﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

using JupiterLibrary;

namespace KinnectInput.KinectVideo
{
    public enum VideoPlayerButtonState
    {
        InActive,
        Active,
        Selected
    }
    public class VideoPlayerButton
    {
        public Sprite SpriteTex { get; private set; }
        public Rectangle ButtonRect;
        public VideoPlayerButtonState PlayerButtonState;
        public float Opacity;

        //aqui el ring
        public Ring SelectionButtonRing;

        public VideoPlayerButton(Texture2D tex, Rectangle buttonSize)
        {
            ButtonRect = buttonSize;
            SpriteTex = new Sprite();
            SpriteTex.SetRectangle(ButtonRect);
            SpriteTex.Texture = tex;
            SpriteTex.Update();
            PlayerButtonState = VideoPlayerButtonState.InActive;
            SelectionButtonRing = new Ring(0, 0, buttonSize.Width / 2, buttonSize.Width / 6);
            SelectionButtonRing.Color = Color.CornflowerBlue;
            SelectionButtonRing.Position = new Vector3(buttonSize.X + buttonSize.Width / 2, buttonSize.Y + buttonSize.Width / 2, 0);
            SelectionButtonRing.Update(); 
        }
        public void Update()
        {

            switch (PlayerButtonState)
            {
                case VideoPlayerButtonState.InActive:
                    
                    SpriteTex.SetAlpha(0.3f);
                    //SpriteTex.DrawEffect(null);
                    break;

                case VideoPlayerButtonState.Active:
                    SpriteTex.SetAlpha(1);
                
                    if (SelectionButtonRing.EndAngle < 361)
                    {
                        SelectionButtonRing.EndAngle += Jupiter.At1Second(361);
                        
                    }
                    else
                    {
                        this.PlayerButtonState = VideoPlayerButtonState.Selected;
                        SelectionButtonRing.StartAngle = 0f;
                        SelectionButtonRing.EndAngle = 0f;
                        SelectionButtonRing.Update();
                    }

                    break;

                case VideoPlayerButtonState.Selected:
                    //esto tiene que ir despues de draw
                    SpriteTex.DrawEffect(Color.White);
                    break;

            }
            SpriteTex.Update();
            SelectionButtonRing.Update();
        }
        public void CheckOnButton(Vector2 posToBe)
        {
            if(ButtonRect.Contains(new Point((int)posToBe.X, (int)posToBe.Y)))
            {
                this.PlayerButtonState=VideoPlayerButtonState.Active;
            }
            else
                this.PlayerButtonState=VideoPlayerButtonState.InActive;
        }
        public void Draw()
        {
            SpriteTex.Draw();
            if(this.PlayerButtonState==VideoPlayerButtonState.Active)
                SelectionButtonRing.Draw(); 
        }
    }
}
